#ifndef _SHARED_BITMATH_H_
#define _SHARED_BITMATH_H_

FORCE_INLINE uint32 CountSetBits( uint32 bitMask )
{
    uint32 LSHIFT = sizeof( uint32 ) * 8 - 1;
    uint32 bitSetCount = 0;
    uint32 bitTest = ( uint32 ) 1 << LSHIFT;    
    for( uint32 n = 0; n <= LSHIFT; n++ )
    {
        bitSetCount += ( ( bitMask & bitTest ) ? 1 : 0 );
        bitTest /= 2;
    }
    return bitSetCount;
}

FORCE_INLINE uint32 CountSetBits( uint64 bitMask )
{
    uint32 LSHIFT = sizeof( uint64 ) * 8 - 1;
    uint32 bitSetCount = 0;
    uint64 bitTest = ( uint64 ) 1 << LSHIFT;    
    for( uint32 n = 0; n <= LSHIFT; n++ )
    {
        bitSetCount += ( ( bitMask & bitTest ) ? 1 : 0 );
        bitTest /= 2;
    }
    return bitSetCount;
}

#endif // _SHARED_BITMATH_H_
